<template>
  <div>
    <div class="all">
      <div class="main">
        <!-- 头部 -->
        <el-row :gutter="20">
          <el-col :span="2" :push="20"
            ><el-button type="success" class="el-icon-edit"
             @click="openadd" >添加菜单</el-button
            ></el-col
          >
        </el-row>
        <!-- 表格 -->
        <el-table :data="tableData" stripe style="width: 100%">
          <el-table-column prop="title" label="标题" width="180">
          </el-table-column>
          <el-table-column prop="authority" label="权限点代码" width="800px">
          </el-table-column>
          <el-table-column prop="operation" label="操作">
             <template slot-scope="scope">
              <el-button type="primary" icon="el-icon-edit" circle></el-button
            ><el-button type="danger" icon="el-icon-delete" circle @click="open(scope.row.id)"></el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- + -->
        <menuAddVue :showdialog.sync="dialogFormVisible" @handleCloseModal="handleClose" :text="text"></menuAddVue>
      </div>
    </div>
  </div>
</template>

<script>
import { list, remove } from '@/api/base/menus.js'
import menuAddVue from '@/module-manage/components/menu-add'
export default {
  components: { menuAddVue },
  data () {
    return {
      dialogFormVisible: false,
      tableData: [
        {

          title: '详情页',
          authority: 'details'
        }
      ],
      text: 'a',
      form: {
        id: null
      }
    }
  },

  created () {
    this.getRenderList()
  },

  methods: {
    async getRenderList () {
      const data = await list()
      this.tableData = data.data
    },
    openadd () {
      this.dialogFormVisible = true
    },
    handleClose () {
      this.dialogFormVisible = false
    },
    open (id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        this.form.id = id
        await remove(this.form)
        this.getRenderList()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>

<style scoped lang="less">
.all {
  padding: 20px;
  .main {
    padding: 20px;
    background-color: #fff;
  }
  .separate {
    margin: 20px 0;
    width: 100%;
    height: 30px;
    background-color: #ccc;
    padding-left: 15px;
    border-radius: 5px;
    p {
      font-size: 18px;
      line-height: 30px;
    }
  }
}
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>
